package demo1.TemplateMethod;

/**
 * @ClassName TemplateMethod
 * @Description TODO
 * @Author 耀酱
 * @Date 2023/6/4 15:38
 * @Version 1.0
 */
// 模板方法模式
public class TemplateMethod {
    public static void main(String[] args) {

        Coffee coffee = new Coffee();
        coffee.prepareRecipe();

        Tea tea = new Tea();
        tea.prepareRecipe();

    }
}
// 模板方法模式
abstract class CaffeineBeverage {
    // 总体步骤
    final void prepareRecipe() {
        boilWater();
        brew();
        pourInCup();
        addCondiments();
    }
    // 变化的内容交给具体子类实现
    abstract void brew();

    abstract void addCondiments();
    // 不变的内容抽象在一个类
    void boilWater() {
        System.out.println("Boiling water");
    }

    void pourInCup() {
        System.out.println("Pouring into cup");
    }
}

class Coffee extends CaffeineBeverage {
    void brew() {
        System.out.println("Dripping Coffee through filter");
    }

    void addCondiments() {
        System.out.println("Adding Sugar and Milk");
    }
}

class Tea extends CaffeineBeverage {
    void brew() {
        System.out.println("Steeping the tea");
    }

    void addCondiments() {
        System.out.println("Adding Lemon");
    }
}
